/*
 * @Author: anxia.ack anchenkai@come-future.com
 * @Date: 2025-03-22 15:40:08
 * @LastEditors: anxia.ack anchenkai@come-future.com
 * @LastEditTime: 2025-03-22 15:40:10
 * @FilePath: /free-learning/src/views/codegen/script.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 轮播图功能
document.addEventListener("DOMContentLoaded", function () {
  const slides = document.querySelectorAll(".slide");
  let currentIndex = 0;

  function showSlide(index) {
    slides.forEach((slide) => slide.classList.remove("active"));
    slides[index].classList.add("active");
  }

  function nextSlide() {
    currentIndex = (currentIndex + 1) % slides.length;
    showSlide(currentIndex);
  }

  // 自动轮播
  setInterval(nextSlide, 5000);

  // 手动轮播
  document.addEventListener("keydown", function (event) {
    if (event.key === "ArrowLeft") {
      currentIndex = (currentIndex - 1 + slides.length) % slides.length;
      showSlide(currentIndex);
    } else if (event.key === "ArrowRight") {
      nextSlide();
    }
  });
});
